package com.itjob.scott.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class InitServlet extends HttpServlet {

	private static final long serialVersionUID = 5969510939288543015L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("init...");
		Cookie cookie = new Cookie("user", new Date().toString());
		
		//600秒  等于10分钟
		cookie.setMaxAge(600);
		response.addCookie(cookie);
		
		//request.getRequestDispatcher("/welcome.jsp").forward(request, response);
		response.sendRedirect(request.getContextPath()+"/welcome.jsp");
		
	}

}
